import java.io.Serializable;
import java.util.Random;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class WriteThread implements Serializable,Runnable{
    @Override
    public void run() {
        while (true){
            Mythread.readlock.lock();
            System.out.println(Thread.currentThread().getName()+":readlock");
            Mythread.readlock.unlock();
            System.out.println(Thread.currentThread().getName()+":readunlock");

            Mythread.writelock.lock();
            System.out.println(Thread.currentThread().getName()+":writelock");

            Mythread.readlock.lock();
            System.out.println(Thread.currentThread().getName()+":readlock");

            System.out.println(Thread.currentThread().getName()+":========put");
            Mythread.writelock.unlock();
            System.out.println(Thread.currentThread().getName()+":writeunlock");
            Mythread.readlock.unlock();
            System.out.println(Thread.currentThread().getName()+":readunlock");

        }

    }

    synchronized void sayhello(){
        System.out.println(Thread.currentThread().getName()+":hello=========");
    }
}
